/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ventas.action;

import static com.opensymphony.xwork2.Action.ERROR;
import static com.opensymphony.xwork2.Action.SUCCESS;
import com.opensymphony.xwork2.ActionSupport;
import com.ventas.bean.Cliente;
import com.ventas.bean.Personal;
import com.ventas.dao.ClienteDao;
import com.ventas.dao.PersonalDao;
import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author jesus
 */
public class PersonalAction extends ActionSupport {
    
    private List<Personal> ListadoPersonal = null;
    Personal personal;
    
    //INGRESO
    String  nomp;
    String apep;
     String dnip;
     Date fecNacp;
    String dirper;
     String sexo;

    public List<Personal> getListadoPersonal() {
        return ListadoPersonal;
    }

    public void setListadoPersonal(List<Personal> ListadoPersonal) {
        this.ListadoPersonal = ListadoPersonal;
    }

    public Personal getPersonal() {
        return personal;
    }

    public void setPersonal(Personal personal) {
        this.personal = personal;
    }

    public String getNomp() {
        return nomp;
    }

    public void setNomp(String nomp) {
        this.nomp = nomp;
    }

    public String getApep() {
        return apep;
    }

    public void setApep(String apep) {
        this.apep = apep;
    }

    public String getDnip() {
        return dnip;
    }

    public void setDnip(String dnip) {
        this.dnip = dnip;
    }

    public Date getFecNacp() {
        return fecNacp;
    }

    public void setFecNacp(Date fecNacp) {
        this.fecNacp = fecNacp;
    }

    public String getDirper() {
        return dirper;
    }

    public void setDirper(String dirper) {
        this.dirper = dirper;
    }

    public String getSexo() {
        return sexo;
    }

    public void setSexo(String sexo) {
        this.sexo = sexo;
    }
     
     
    
      public String cargaIngresoPersonal() throws Exception {
       
        try {            
            System.out.println("Exito cargaSelectMarcasAction");
            ListadoPersonal();
        } catch (Exception e) {
            System.out.println("Error cargaSelectMarcasAction" + e.getMessage());
            e.printStackTrace();
        }
        return SUCCESS;
    }
    
    
    public String ListadoPersonal() throws Exception {
       
        ListadoPersonal= new ArrayList<>();
        
     
        try {
            PersonalDao personalDao = new PersonalDao();
            
            ListadoPersonal=personalDao.listadoPersonalActivos();
            
            System.out.println("Exito ");
        } catch (Exception e) {
            System.out.println("Error de Action" + e.getMessage());
            e.printStackTrace();
        }
        if (ListadoPersonal.isEmpty()) {
            return ERROR;
        } else {
            return SUCCESS;
        }
    }
    
   
      public String IngresoPersonal() throws Exception {
        boolean resultado = false;
        try {
           PersonalDao personalDao = new PersonalDao();
           Personal personal = new Personal();
           
                   
            
            personal.setPer_nombres(nomp);
            personal.setPer_apellidos(apep);
            personal.setPer_dni(dnip);
            personal.setPer_fecNacimiento(fecNacp);
             personal.setPer_direccion(dirper);
            personal.setPer_sexo(sexo);
            
                   
                       
            resultado = personalDao.IngresoPersonalDao(personal);
            System.out.println("Exito de Action-Ingreso");
        } catch (Exception e) {
            System.out.println("Error de Action" + e.getMessage());
            e.printStackTrace();
        }
        
        ListadoPersonal();
        cargaIngresoPersonal();
        if (resultado) {
            addActionMessage("Ingreso Exitoso");
            return SUCCESS;
            
        } else {
            addActionError("No se pudo Ingresar");
            return ERROR;
        }
    }
    
    

}
